package com.thoughtworks.studentManagement.service;

import com.thoughtworks.studentManagement.exception.StudentNotFoundException;
import com.thoughtworks.studentManagement.model.Student;
import com.thoughtworks.studentManagement.repository.StudentRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {

    private final StudentRepository repository;

    StudentService(StudentRepository repository) {
        this.repository = repository;
    }

    public List<Student> findAllStudents() {
        return repository.findAll();
    }

    public Student findAStudent(String studentNumber) {
        return repository.findById(studentNumber)
                .orElseThrow(() -> new StudentNotFoundException(studentNumber));

    }
}
